package com.atguigu.fastdfs;

import org.csource.common.MyException;
import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.util.ClassUtils;


/**
 * @author wk
 * @create 2021-08-26 11:21
 */
public class FastDFS {
    public static void main(String[] args) throws Exception {
        // 1.设置跟踪器的IP和端口号
        // String path1 = FastDFS.class.getClass().getClassLoader().getResource("fdfs_client.conf").getPath();
        // 使用工具类获取到文件的路径
        String path = ClassUtils.getDefaultClassLoader().getResource("fdfs_client.conf").getPath();
        ClientGlobal.init(path);
        // 2.客户端连接跟踪器
        TrackerClient client = new TrackerClient();
        // 3.获取存储结点的IP和端口号
        TrackerServer trackerServer = client.getConnection();
        StorageClient1 storageClient1 = new StorageClient1(trackerServer, null);
        // 4.存储文件
        String fileId = storageClient1.upload_file1("E:\\尚品汇商城\\电商前端静态资源\\img\\2.jpg", "jpg", null);
        System.out.println(fileId);
        // http://192.168.57.131:8080/group1/M00/00/00/wKg5g2EnN-iAKKJFAAB2guY9Uzw245.jpg
    }
}
